package in.hitmedia.test.bitswise;

public class CTCI_5_2 
{
	public static int merge(int n, int m, int i, int j)
	{
		int allOnes = ~0;
		
		int left = allOnes << (j+1);
		int right = (1 << i) - 1;
		
		int mask = left | right;
		int nCleared = n & mask;
		int mShifted = m << i;
		
		return nCleared | mShifted;
	}
	
	public static void main(String args[])
	{
		int n = 0x1000000;
		int m = 0X13;
		System.out.println(Integer.toBinaryString(n));
		System.out.println(Integer.toBinaryString(m));
		System.out.println(Integer.toBinaryString(merge(n, m, 1, 6)));
		
		
	}
	
	
}
